/* eslint-disable */
/**
 * Created by GYL on 2018/8/24
 */
//项目进度管理
import React, { Component } from 'react';
import Filtrate from '../../components/common/Filtrate';
import Container from "../../components/common/Container";
import MyTable from "../../components/common/MyTable";
import PublicService from "../../services/PublicService";
import PublicTemplate  from '../../services/PublicTemplate';
import request from '../../utils/request';
import Progess_Adjust from './Progess_Adjust';
import MyPagination from "../../components/common/MyPagination";
import { message, Divider, Tag, Spin} from 'antd';
import GtteWrap from './sub/GtteWrap';
import style from './Progess.less';

class Progess extends Component {

  state = {
    // status: "",
    params: {},
    pageSize: 10,
    pageIndex: 1,
    total: 0,
    delConfirm: false,
    addModal: false,
    selectedRowKeys: [],
    dataSate: [],
    addWrap: true,
    editWrap: false,
    EditArr: [],
    AddArr: [],
    GtteWrapId: '',
    spinning: false,
    progessAdjustData: {},
    xmmc: [],
    ywjl: [],
    xmfzr: [],
    qyfzr: []
  }
  componentDidMount() {
    this.onSubmit(1, 10)

    this.dropDownBoxTwo()
  }
  dropDownBoxTwo = () => {
    request({
      url: '/pm-web/projectmanage/findData/dropDownBoxTwo',
      method: 'GET',
      params: {
        userId: PublicService.getCookie('userId')
      }
    }).then(data => {

      if (data.rc === 0) {
        this.setState({
          xmmc: data.ret.xmmc,
          ywjl: data.ret.ywjl,
          xmfzr: data.ret.xmfzr,
          qyfzr: data.ret.qyfzr,
        })
      }
    })
  }

  //查询
  onSubmit = (page, size) => {
    const params = this.f1.getForm().getFieldsValue();
    params.page = page;
    params.rows = size;
    params.menuType = '1'
    params.userId = PublicService.getCookie('userId'),
      this.setState({
        params,
        spinning: true,
        pageIndex: page,
        pageSize: size
      })
    this.getAllTabulateData(params);
    request({
      url: '/pm-web/projectmanage/projectinfo/getAllProjectInfo',
      method: 'POST',
      data: params
    }).then(data => {

      if (data.rc === 0) {
        this.setState({
          dataSate: data.ret.items,
          spinning: false,
          total: data.ret.rowCount,
          selectedRowKeys: [],
        })
      }
    })
  }
  //查询列表数据
  getAllTabulateData = (params) => {
    request({
      url: '/pm-web/projectmanage/projectinfo/getAllTabulateData',
      method: 'POST',
      data: { userId: PublicService.getCookie('userId'), ...params }
    }).then(data => {
      if (data.rc === 0) {
        this.setState({
          progessAdjustData: data.ret
        })
      }
    })
  }

  //重置
  ResetForm = () => {
    console.log('重置')
    this.setState({
      pageIndex: 1,
      pageSize: 10
    }, () => {
      this.onSubmit(1, 10)
    })
  }

  //新增
  addBtnText = () => {
    // console.log('新增')
    this.setState({
      addWrap: true
    })
  }

  // 取消保存
  ModalCancel = (type) => {
    let t = this;
    t.setState({
      [type]: false,
      modalBtnLoading: false
    })
  };

  //多选
  onSelectChange = (selectedRowKeys, row) => {
    // console.log(selectedRowKeys, row)
    if (selectedRowKeys.length < 1) {
      this.setState({ selectedRowKeys, row })
    } else {
      this.setState({
        selectedRowKeys: [selectedRowKeys[selectedRowKeys.length - 1]],
        row: [row[row.length - 1]]
      })
    }

  };

  //查看
  editBtn = () => {
    if (this.state.selectedRowKeys.length !== 1) {
      message.warning('只能对单一事件编辑!')
      return
    }
    if (this.state.dataSate[this.state.selectedRowKeys[0]].status != 2 || this.state.dataSate[this.state.selectedRowKeys[0]].configurationStatus != 5) {
      message.warning('项目未配置')
      return
    }
    this.setState({
      GtteWrap: true,
      GtteWrapId: this.state.dataSate[this.state.selectedRowKeys[0]].projectId
    })
  }


  onTag = (v) => {
    // console.log(v)
    this.setState({
      status: v
    })
    setTimeout(() => {
      this.onSubmit(1, 10)
    }, 500)

  }

  onBack = () => {
    this.setState({
      GtteWrap: false,

    })

    setTimeout(() => {
      this.onSubmit(1, 10)
    }, 200)

  }

  //导出
  exportBtn = (val) => {
    let t = this;
    let isAll = val === 'all' ? true : false;
    window.location.href = '/pm-web/projectmanage/projectinfo/exportProjectMessageThree?' + PublicService.paramSerializer({
      ...t.state.params,
      isAll
    })
  };
  //甘特图主体
  getGtteWrap = () => {
    return (
      <GtteWrap
        id={this.state.GtteWrapId}
        onBack={this.onBack}
      />
    )
  }

  //首页主体
  getWarpBox = () => {
    let t = this;
    let width = document.body.clientWidth;
    const height = document.body.clientHeight;
    let containerHeight = '72vh';
    let tableHeight = 380;
    if (width < 1920) {
      tableHeight = 380;
      containerHeight = '61vh';
    }
    const { xmmc, ywjl, xmfzr, qyfzr, pageSize, pageIndex, selectedRowKeys, total, dataSate, delConfirm, params, progessAdjustData } = this.state
    let rowSelection = {
      selectedRowKeys,
      onChange: this.onSelectChange.bind(this),
    };

    const items = [
      {
        type: 'autoComplete',
        label: '项目名称',
        placeholder: '请输入 ..',
        paramName: 'projectName',
        options:xmmc,
        width:240
      },
      {
        type: 'autoComplete',
        label: '区域负责人',
        placeholder: '请输入 ..',
        paramName: 'areaManagerName',
        options: qyfzr
      },
      {
        type: 'autoComplete',
        label: '项目负责人',
        placeholder: '请输入 ..',
        paramName: 'projectManagerName',
        options: xmfzr
      },
      {
        type: 'select',
        label: '项目状态',
        paramName: 'projectStatus',
        width:120,
        options: [
          { text: '全部', value: '' },
          { text: '正常', value: '1' },
          { text: '变更', value: '2' },
          { text: '冻结', value: '3' },
          { text: '完成', value: '4' },
          { text: '逾期开始', value: '5' },
          { text: '逾期结束', value: '6' },
        ],
      },
    ];



    const columns = [
      { title: '序号', dataIndex: 'num', width: 50, fixed: 'left' },
      { title: '项目名称', dataIndex: 'projectName', key: 'projectName', width: 200, fixed: 'left' },
      { title: '项目编号', dataIndex: 'projectNumber', key: 'projectNumber', width: 150 },
      { title: '项目负责人', dataIndex: 'projectManagerName', key: 'projectManagerName', width: 150, align: 'center' },
      { title: '区域负责人', dataIndex: 'areaManagerName', key: 'areaManagerName', width: 100, align: 'center' },
      { title: '负责人联系方式', dataIndex: 'projectContactWay', key: 'projectContactWay', width: 150, align: 'center' },
      {
        title: '事件配置状态', dataIndex: 'pzType', key: 'pzType', width: 150, align: 'center',
      },
      { title: '项目进度状态', dataIndex: 'projectType', key: 'projectType', width: 150, align: 'center' },
      {
        title: '付款方式', dataIndex: 'paymentMethod', key: 'paymentMethod', width: 150, align: 'center',
        render: (text, record, index) => <span>
          {PublicTemplate.stringToEllipsis(text, 30)}
        </span>
      },
      { title: '中标日期', dataIndex: 'winningBidDate', key: 'winningBidDate', width: 150, align: 'center' },
      { title: '中标金额(万元)', dataIndex: 'winningBidSum', key: 'winningBidSum', width: 150 },
      { title: 'CRM计划开始时间', dataIndex: 'planStartTime', key: 'planStartTime', width: 150 },
      { title: 'CRM计划结束时间', dataIndex: 'planEndTime', key: 'planEndTime', width: 150 },
      { title: 'CRM计划工期', dataIndex: 'workTime', key: 'workTime', width: 150 },
      { title: '平台计划开始时间', dataIndex: 'startTime', key: 'startTime', width: 150 },
      { title: '平台计划结束时间', dataIndex: 'endTime', key: 'endTime', width: 150 },
      { title: '平台计划工期', dataIndex: 'workNum', key: 'workNum', width: 150 },

      { title: '前期计划开始时间', dataIndex: 'qq_k', key: 'qq_k', width: 150 },
      { title: '前期计划结束时间', dataIndex: 'qq_j', key: 'qq_j', width: 150 },
      { title: '项目前期状态', dataIndex: 'qq_z', key: 'qq_z', width: 150 },
      { title: '实施计划开始时间', dataIndex: 'ss_k', key: 'ss_k', width: 150 },
      { title: '实施计划结束时间', dataIndex: 'ss_j', key: 'ss_j', width: 150 },
      { title: '项目实施状态', dataIndex: 'ss_z', key: 'ss_z', width: 150 },
      { title: '验收计划开始时间', dataIndex: 'ys_k', key: 'ys_k', width: 150 },
      { title: '验收计划结束时间', dataIndex: 'ys_j', key: 'ys_j', width: 150 },
      { title: '项目验收状态', dataIndex: 'ys_z', key: 'ys_z', width: 150 },
      { title: '结算计划开始时间', dataIndex: 'js_k', key: 'js_k', width: 150 },
      { title: '结算计划结束时间', dataIndex: 'js_j', key: 'js_j', width: 150 },
      { title: '项目结算状态', dataIndex: 'js_z', key: 'js_z', width: 150 },

      { title: '主要工艺', dataIndex: 'theMainProcess', key: 'theMainProcess', width: 150 },
      { title: '项目地点', dataIndex: 'projectSite', key: 'projectSite', width: 150 },
      { title: '单位分类', dataIndex: 'unitClassification', key: 'unitClassification', width: 150 },
      { title: '单位名称', dataIndex: 'unitName', key: 'unitName', width: 150 },
      { title: '业务经理', dataIndex: 'serviceManagerName', key: 'serviceManagerName', width: 150 },
      { title: '业务经理电话', dataIndex: 'serviceContactWay', key: 'serviceC31ontactWay', width: 150 },
      { title: '计划产值(元)', dataIndex: 'planProduction', key: 'planProduction', width: 150 },
      { title: '累计完成产值(元)', dataIndex: 'accomplishProduction', key: 'accomplishProduction', width: 150 },
      { title: '产值完成比例', dataIndex: 'completeProportion', key: 'completeProportion', width: 150 },
      { title: '项目预算执行率', dataIndex: 'implementationRate', key: 'implementationRate', width: 150 },
      { title: '项目已发生成本(元)', dataIndex: 'incurredCost', key: 'incurredCost', width: 150 },
      { title: '累计应收款额(元)', dataIndex: 'collectedAmount', key: 'collectedAmount', width: 150 },
      { title: '本月回款(元)', dataIndex: 'monthMoney', key: 'monthMoney', width: 150 },
      { title: '本年回款(元)', dataIndex: 'yearMoney', key: 'yearMoney', width: 150 },
      { title: '累计回款(元)', dataIndex: 'grandTotalMoney', key: 'grandTotalMoney', width: 150 },
    ];

    return (
      <div style={{ flex: 1 }}>
        <Spin spinning={this.state.spinning} size='large'>

          <Filtrate
            items={items}
            ref={ref => { this.f1 = ref }}
            submit={this.onSubmit.bind(this, 1, 10)}
            ResetForm={this.ResetForm}
            params={params}
          />
          <Progess_Adjust progessAdjustData={progessAdjustData} />
          <Container
            style={{ height: containerHeight, position: "relative", padding: 10, marginTop: 5 }}
            examineBtn={this.editBtn}
            examineBtnShow={true}
            exportBtnShow={true}
            exportBtn={t.exportBtn.bind(t)}>
            <MyTable
              rowSelection={rowSelection}
              scroll={{ y: height - tableHeight, x: 5000 }}
              columns={columns}
              dataSource={PublicService.transformArrayData(dataSate, true, true, pageIndex, pageSize)}
              pagination={false}
            />
            <MyPagination
              showPage
              pageSize={pageSize}
              current={this.state.pageIndex}
              total={total}
              showSizeChanger
              showQuickJumper
              onChange={this.onSubmit}
              onShowSizeChange={this.onSubmit}
            />
          </Container>
        </Spin>
      </div>
    )
  }

  render() {

    return (

      <div className={style.Warp_box}>
        {this.state.GtteWrap && this.getGtteWrap()}
        {!this.state.GtteWrap && this.getWarpBox()}
      </div>
    );


  }
}
export default Progess;

